// pages/circle/circle.js
const arrayBuffer = new Uint8Array([11, 22, 33])
const base64 = wx.arrayBufferToBase64(arrayBuffer)
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: '',
    ip: '',
    iconshoucang: 'icon-shoucang',
    iconxihuan: 'icon-xihuan',
    iconcomment: 'icon-xinxi',
    imgDisplay: '',
    imgSrc: '',
    listlen: 0,
    imgList: '',
    post_id: 1,
    imageName: ''
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
    var app = getApp()
    var ip = app.globalData.ServerAddress
    let that = this
    that.setData({
      ip: ip
    })
    wx.showLoading({
      title: '数据加载中...',
    })
    wx.request({
      url: "http://" + ip + "/post/all",
      method: 'GET',
      dataType: "json",
      header: {
        'Content-type': 'application/json',
        
        "authorization": app.globalData.token
      },
      data: {
        "is_search": "false",
        "page": 1,
        "per_page": 100,
        "search_info": "none",
        "is_personal": "f"
      },
      success: function (res) {
        console.log(res)
        that.setData({
          list: res.data.posts
        })
      },
      complete: () => {
        //隐藏loading效果
        wx.hideLoading()
      }
    }),
    // wx.request({
    //   url: "http://" + ip + "/post/all",
    //   method: 'GET',
    //   dataType: "json",
    //   header: {
    //     'Content-type': 'application/json',
        
    //     "authorization": app.globalData.token
    //   },
    //   data: {
    //     "is_search": "false",
    //     "page": 1,
    //     "per_page": 100,
    //     "search_info": "none",
    //     "is_personal": "f"

    //   },
    //   success: function (res) {
    //     console.log(res)
    //     that.setData({
    //       list: res.data.posts,
    //       // listlen: res.data.posts.length
    //     })
    //     console.log(that.data.listlen);
        
    //   }
    // });
      wx.request({
        // url: "http://" + ip + "/post/media",
        method: 'GET',
        dataType: "json",
        // responseType:"arraybuffer",
        header: {
          'Content-type': 'application/json',
          
        "authorization": app.globalData.token
        },
        data: {
          "post_id": 1,
          "return_method": "LIST",
          "name": 'none',
        },
        success: function (res) {
          console.log(res)
          that.setData({
            imgList: res.data.data_list,
            imageName: res.data.data_list
          })
          console.log(that.data.imgList)
          
          
        }
      })
  },
  getCode(){
    var app = getApp()
    var ip = app.globalData.ServerAddress
    let that = this
    console.log(that.data.imgList[0])
    wx.request({
      url: "http://" + ip + "/post/media",
      method: 'GET',
      dataType: "json",
      // responseType:"arraybuffer",
      header: {
        'Content-type': 'application/json',
        
        "authorization": app.globalData.token
      },
      data: {
        "post_id": 1,
        "return_method": "DATA",
        "name": that.data.imgList[0],
      },
      success: function (res) {
        console.log(res)
        that.setData({
          imgSrc: res,
        })
        console.log(res)
      }
    })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  onScrollToUpper: function (){
    this.onLoad()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.onLoad()
  },
  onRefresh:function(){
    //导航条加载动画
    wx.showNavigationBarLoading()
    //loading 提示框
    wx.showLoading({
      title: 'Loading...',
    })
    console.log("下拉刷新啦");
    setTimeout(function () {
      wx.hideLoading();
      wx.hideNavigationBarLoading();
      //停止下拉刷新
      wx.stopPullDownRefresh();
    }, 2000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})